package cn.crm;

import cn.crm.entiy.Customer;
import cn.crm.entiy.User;
import cn.crm.service.CustomerService;
import cn.crm.service.CustomerServiceImpl;
import cn.crm.service.UserService;
import cn.crm.service.UserServiceImpl;

import java.util.Scanner;

public class Main {
    static Scanner input = new Scanner(System.in);

    static UserService userService = new UserServiceImpl();

    static CustomerService customerService = new CustomerServiceImpl();

    static User loginUser=null;
    static Customer customer = null;
    public static void main(String[] args) {
        while (true){
            System.out.println("XX客户关系管理系统\n" +
                    "1.登录系统\n" +
                    "2.退出系统");
            switch (input.nextInt()){
                case 1:
                    login();
                    break;
                case 2:
                    System.out.println("Bey！！");
                    return;
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }

    }

    public static void login(){
        System.out.println("请输入用户名：");
        String username = input.next();
        System.out.println("请输入密码：");
        String password = input.next();
        loginUser = userService.login(username,password);
        if(loginUser!=null){
            manage();
        }
    }

    public static void manage(){
        while (true){
            System.out.println("欢迎回来："+loginUser.getName());
            System.out.println("1.录入客户信息   \n" +
                    "2.客户管理  \n" +
                    "3.退出");
            switch (input.nextInt()){
                case 1:
                    System.out.println("请输入公司名称:");
                    String company = input.next();

                    System.out.println("请输入电话:");
                    String phone = input.next();

                    System.out.println("请输入联系人:");
                    String manager = input.next();

                    customer = new Customer(company,phone,manager);

                    customerService.add(customer);

                    //录入客户信息,作业完成
                    break;
                case 2:
                    customerManage();
                    break;
                case 3:
                    System.out.println("谢谢使用！！");
                    System.exit(0);
                default:
                    System.out.println("输入有误，请重新输入");
            }
        }
    }
    public static void customerManage(){
        while (true){
            customerService.showList(loginUser);
            System.out.println("请输入编号选择用户：");
            customer = customerService.getCustomer(input.nextInt());
            if(customer!=null){
                System.out.println("1.更换跟进人  \n" +
                        "2.新增访问记录   \n" +
                        "3.查询访问记录  \n" +
                        "4.返回");
                switch (input.nextInt()){
                    case 1:
                        System.out.println("请输入要更换的跟进人");
                        customerService.update(customer,new User("1","1",input.next()));
                        break;
                    case 2:
                        System.out.println("请输入新增记录信息");
                        customerService.addRecord(customer,input.next());
                        break;
                    case 3:
                        customerService.showRecordList(customer);
                        break;
                    case 4:
                        return;
                    default:
                        System.out.println("输入有误，请重新输入");
                }
            }
        }
    }
}
